package com.it.iostream.Controller;


import com.it.iostream.Dao.ResPonseResult;
import com.it.iostream.Service.Impl.FtpServiceImpl;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/*
* Ftp上传文件
* */
@RestController
@RequestMapping(value = "/FtpFile")
public class FtpController {

    @Resource
    private FtpServiceImpl ftpService;

    /*
    *ipAddress 虚拟机地址
    *userName 虚拟机账户
    *password 虚拟机密码
    * */

    /*
    *@先登录上传文件
    * linuxsrc Linux内文件名
    * file 本地文件名
    * */
    @RequestMapping(value = "/upload")
    public ResPonseResult  uploadfile(@NotNull @NotEmpty @RequestParam(value = "ipAddress") String ipAddress,
                             @NotNull @NotEmpty  @RequestParam(value = "userName") String userName,
                             @NotNull @NotEmpty  @RequestParam(value = "password") String password,
                             @NotNull @NotEmpty @RequestParam(value = "linuxsrc")String linuxsrc,
                             @NotNull @NotEmpty @RequestParam(value = "file")String file) throws Exception {
     return   ftpService.uploadfile(ipAddress,userName,password,linuxsrc,file);
    }

    /**
     *@下载文件
     * linuxsrc Linux服务器文件地址
     * localaddr 存放本地的文件地址
     * 采用OverWrite方式
     */
    @RequestMapping(value = "/download")
    public ResPonseResult downloadfile(@NotNull @NotEmpty @RequestParam(value = "ipAddress") String ipAddress,
                                       @NotNull @NotEmpty  @RequestParam(value = "userName") String userName,
                                       @NotNull @NotEmpty  @RequestParam(value = "password") String password,
                                       @NotNull @NotEmpty @RequestParam(value = "linuxsrc")String linuxsrc,
                                       @NotNull @NotEmpty @RequestParam(value = "localaddr")String localaddr) throws Exception {
      return  ftpService.downloadfile(ipAddress,userName,password,linuxsrc,localaddr);
    }

    /*
    *@删除文件
    * linuxsrc Linux服务器文件地址
    */
    @RequestMapping(value = "/delete")
    public ResPonseResult deletefile(@NotNull @NotEmpty @RequestParam(value = "ipAddress") String ipAddress,
                             @NotNull @NotEmpty  @RequestParam(value = "userName") String userName,
                             @NotNull @NotEmpty  @RequestParam(value = "password") String password,
                             @NotNull @NotEmpty @RequestParam(value = "linuxsrc")String linuxsrc) throws Exception {
        return  ftpService.deletefile(ipAddress,userName,password,linuxsrc);
    }




}
